package a.b.reggie.controller;

import a.b.reggie.common.R;
import a.b.reggie.dto.OrdersDto;
import a.b.reggie.pojo.Orders;
import a.b.reggie.service.IOrderService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private IOrderService orderService;

    /**
     * 添加订单
     * @param request
     * @param ordersDto
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(HttpServletRequest request, @RequestBody OrdersDto ordersDto){
        Long phone = Long.valueOf(String.valueOf(request.getSession().getAttribute("user")));
        log.info("ordersDto"+ordersDto.toString());
        orderService.submit(phone,ordersDto);
        return R.success("提交成功");
    }

    /**
     * 用户获取订单分页信息
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page<OrdersDto>> userPage(int page,int pageSize,HttpServletRequest request){
        Object phone = request.getSession().getAttribute("user");
        Page page1 = orderService.Upage(phone,page,pageSize);
        return R.success(page1);
    }

    /**
     * 商家获取订单分页信息
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<Page<OrdersDto>> page(int page, int pageSize, Long number,String beginTime,String endTime){
        log.info("beginTime  "+beginTime,"endTime  "+endTime);
        Page page1 = orderService.Spage(page,pageSize,number,beginTime,endTime);

        return R.success(page1);
    }

    /**
     * 派送订单
     * @param map
     * @return
     */
    @PutMapping
    public R<String> updateStatus(@RequestBody Map map){
        orderService.updateStatus(map);
        return R.success("修改成功");
    }



}
